/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* foobar-calc
* Copyright (C) wei lichun 2008 <selina_only@sina.com>
* 
* foobar-calc is free software.
* 
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
* 
* foobar-calc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with foobar-calc.  If not, write to:
* 	The Free Software Foundation, Inc.,
* 	51 Franklin Street, Fifth Floor
* 	Boston, MA  02110-1301, USA.
*/

#ifndef _C_AUTO_MACHINE_HPP_
#define _C_AUTO_MACHINE_HPP_


#include "mystring.h"
#include "memory.h"
//#include "mystack.h"
#include <stack>
class CAutoMata  
{
public:
	CAutoMata();
	virtual ~CAutoMata();
	//************************************
	// Method:    acceptInstruction
	// FullName:  CAutoMata::acceptInstruction
	// Access:    public 
	// Returns:   int
	// Parameter: int data
	//************************************
	int acceptInstruction(int data);//returns machine state
	//************************************
	// Method:    acceptInstruction
	// FullName:  CAutoMata::acceptInstruction
	// Access:    public 
	// Returns:   int
	// Qualifier:
	// Parameter: int data	data=操作命名,加减乘除正弦等
	// Parameter: int type	type=[RAD|DEG|GRD]
	//************************************
	int acceptInstruction(int data,int type);//RAD,DEG...
	//************************************
	// Method:    getDisplay
	// FullName:  CAutoMata::getDisplay
	// Access:    public 
	// Returns:   std::string
	// Qualifier:
	//************************************
	mystring getDisplay();
	bool hasMemoryStored();
	void reset();
protected:
	int mState;
	CMemory memory;
	mystring mDisplay;
	int mBracketCount;
	void error();
	void trim0();
	//************************************
	// Method:    updateStack
	// FullName:  CAutoMata::updateStack
	// Access:    protected 
	// Returns:   void
	// Qualifier:
	// Parameter: int op
	//************************************
	void updateStack(int op);
	//Stacks
	std::stack<double> mStackOperand;
	std::stack<int>	mStackOperator;//操作符
	bool err;


};

#endif // _C_AUTO_MACHINE_HPP_
